﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;
using UBConDemo.Models;
using System.Windows;
using System.Windows.Controls;
using UBCon.Ribbon;
using UBConDemo.Views.Ribbon;

namespace UBConDemo.CustomControls
{
    public class UbConItem:ButtonBase
    {
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------
        #region Constructors

        static UbConItem() 
        {
            Type ownerType = typeof(UbConItem);

            DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));

            
        }

        #endregion

        //------------------------------------------------------
        //
        //  Properties
        //
        //------------------------------------------------------
        #region Properties
        #endregion

        //------------------------------------------------------
        //
        //  Depenency Property Changed Callbacks
        //
        //------------------------------------------------------
        #region Depenency Property Changed Callbacks
        #endregion

        //------------------------------------------------------
        //
        //  Overrides
        //
        //------------------------------------------------------
        #region Overrides

        /// <summary>
        /// Raises System.Windows.Controls.Primitives.ButtonBase.Click event.
        /// </summary>
        protected override void OnClick()
        {
            base.OnClick();
            UbConItemModel model = DataContext as UbConItemModel;
            if (model != null && !model.IsCategoryNameItem)
            {
                UbConItemsControl itemsConrol = ItemsControl.ItemsControlFromItemContainer(this) as UbConItemsControl;
                if (itemsConrol != null)
                {
                    if (model.ShowInAnotherWindow)
                    {
                        if (string.Compare(model.ViewType, "RibbonWindowView") == 0) 
                        {
                            RibbonWindowView _view = new RibbonWindowView();
                            _view.ShowDialog();
                        }
                        else if (string.Compare(model.ViewType, "DefaultWindowView") == 0) 
                        {
                            DefaultWindowView _view = new DefaultWindowView();
                            _view.ShowDialog();
                        }

                    }
                    else
                    {
                        int selectedIndex = itemsConrol.ItemContainerGenerator.IndexFromContainer(this);
                        itemsConrol.SetValue(UbConItemsControl.SelectedIndexProperty, selectedIndex);
                        itemsConrol.ShowView();
                    }
                }
            }
        }

        #endregion

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------
        #region Public Methods
        #endregion

        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------
        #region Internal Methods
        #endregion

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        #region Private Methods
        #endregion

        //------------------------------------------------------
        //
        //  Event Handlers
        //
        //------------------------------------------------------
        #region Event Handlers
        #endregion

        //------------------------------------------------------
        //
        //  Fields
        //
        //------------------------------------------------------
        #region Fields
        #endregion

        //------------------------------------------------------
        //
        //  Events
        //
        //------------------------------------------------------
        #region Events
        #endregion

        //------------------------------------------------------
        //
        //  Commands
        //
        //------------------------------------------------------
        #region Commands
        #endregion

    }
}
